<?php 
namespace Api\Controller;
class WxappapiController extends CommonController{
	
	protected $sms;
	protected $apiService;

	
	function _initialize() {
		parent::_initialize();
		$this->sms = D('Sms');
		$this->apiService = D('Api','Service');
	}
	
	//发送短信
	public function sendsms(){
		$mobile = I('mobile');
		$code = rand(100000,999999);
		$type = I('type');
		if($this->apiService->_send_sms($mobile,$code,$type)){
			_apiReturn(1,'发送成功');
		}else{
			_apiReturn(0,'发送失败');
		}
	}
	
	//判断验证码对错
	public function marrysms(){
		$mobile = I('mobile');
		$code = I('code');
		$type = I('type');
		if($this->sms->where(array('mobile'=>$mobile,'code'=>$code,'type'=>$type,'token_time'=>array('gt',time())))->find()){
			_apiReturn(1,'验证码正确');
		}else{
			_apiReturn(0,'验证码错误');
		}
	}
	
	//获取订单
	public function getOrders(){
		$uid = 693;
		$p = I("p");
		$pagesize = I('pagesize')?I("pagesize"):10;
		$list = D('YgclOrder')->where(array('uid'=>$uid))->relation(true)->page($p,$pagesize)->order('id desc')->select();
		$data = array('status'=>1,'info'=>"获取成功",'data'=>$list);
		$this->ajaxReturn($data);
	}
	
	public function getSchoolDetail(){
		$data = M('MaterialSingle')->where(array('key'=>'school'))->find();
		_apiReturn(1,'success',$data);
	}
	
}